﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace V5_EaspLibs.Core {
    /// <summary>
    /// 错误类
    /// </summary>
    public class ErrorHelper {
        private static readonly ErrorHelper m_Instance = new ErrorHelper();
        /// <summary>
        /// 
        /// </summary>
        public static ErrorHelper Instance {
            get { return m_Instance; }
        }
        /// <summary>
        /// 
        /// </summary>
        public ErrorHelper() {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="me"></param>
        /// <returns></returns>
        public string ErrorInfoException(Exception me) {
            return "Source: " + me.Source +
                "<br>Message: " + me.Message +
                "<br>Stack trace: " + me.StackTrace;
        }

        /// <summary>
        /// 显示错误信息
        /// </summary>
        /// <param name="ErrMsg">错误字符串</param>
        public void ShowErrorPage(string ErrMsg) {
            HttpContext current = HttpContext.Current;
            current.Response.Write("<html>");
            current.Response.Write("<body style=\"font-size:14px;\">");
            current.Response.Write("Error:<br />");
            current.Response.Write("<textarea name=\"errormessage\" style=\"width:95%; height:95%; word-break:break-all\">");
            current.Response.Write(HttpUtility.HtmlEncode(ErrMsg));
            current.Response.Write("</textarea>");
            current.Response.Write("</body></html>");
            current.Response.End();
        }
    }
}
